<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="案例篇：疫情数据可视化, 张亚飞,飞凡空间,国学,Python,Go">
    <meta name="description" content="2020年因为新冠疫情而变得特别，我们会看到很多网站都提供了多种疫情统计图，今天我们使用 Python 的 pyecharts 框架来绘制一些比较常见的统计图。
本项目源码已上传至gitee: 项目地址
一、玫瑰图首先，我们来绘制前段时间比">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
	<meta name="baidu-site-verification" content="code-w2ezfaoXE0" />
    <title>案例篇：疫情数据可视化 | 飞凡空间</title>
    <link rel="icon" type="image/png" href="/medias/my-logo.png">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/all.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">
    
    <script src="/libs/jquery/jquery.min.js"></script>
    
<meta name="generator" content="Hexo 5.2.0">
<style>.github-emoji { position: relative; display: inline-block; width: 1.2em; min-height: 1.2em; overflow: hidden; vertical-align: top; color: transparent; }  .github-emoji > span { position: relative; z-index: 10; }  .github-emoji img, .github-emoji .fancybox { margin: 0 !important; padding: 0 !important; border: none !important; outline: none !important; text-decoration: none !important; user-select: none !important; cursor: auto !important; }  .github-emoji img { height: 1.2em !important; width: 1.2em !important; position: absolute !important; left: 50% !important; top: 50% !important; transform: translate(-50%, -50%) !important; user-select: none !important; cursor: auto !important; } .github-emoji-fallback { color: inherit; } .github-emoji-fallback img { opacity: 0 !important; }</style>
<link rel="alternate" href="/atom.xml" title="飞凡空间" type="application/atom+xml">
<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css">
<link rel="stylesheet" href="/css/prism-line-numbers.css" type="text/css"></head>


<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/medias/my-logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">飞凡空间</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/friends" class="waves-effect waves-light">
      
      <i class="fas fa-address-book" style="zoom: 0.6;"></i>
      
      <span>友情链接</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/contact" class="waves-effect waves-light">
      
      <i class="fas fa-comments" style="zoom: 0.6;"></i>
      
      <span>留言板</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>

<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/my-logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">飞凡空间</div>
        <div class="logo-desc">
            
            诚者，天之道也；诚之者，人之道也。诚者，不勉而中，不思而得。从容中道，圣人也；诚之者，择善而固执者也。
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/friends" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-address-book"></i>
			
			友情链接
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/contact" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-comments"></i>
			
			留言板
		</a>
          
        </li>
        
        
    </ul>
</div>

        </div>

        
    </nav>

</header>

    



<div class="bg-cover pd-header post-cover" style="background-image: url('https://zhangyafei-1258643511.cos.ap-nanjing.myqcloud.com/Python/blog/pandas-7.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <div class="description center-align post-title">
                        案例篇：疫情数据可视化
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        margin: 35px 0 15px 0;
        padding-left: 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #toc-content .is-active-link::before {
        background-color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/tags/Python%E4%B9%8B%E8%B7%AF/">
                                <span class="chip bg-color">Python之路</span>
                            </a>
                        
                            <a href="/tags/%E7%88%AC%E8%99%AB/">
                                <span class="chip bg-color">爬虫</span>
                            </a>
                        
                            <a href="/tags/pandas/">
                                <span class="chip bg-color">pandas</span>
                            </a>
                        
                            <a href="/tags/%E6%A1%88%E4%BE%8B%E7%AF%87/">
                                <span class="chip bg-color">案例篇</span>
                            </a>
                        
                            <a href="/tags/%E5%8F%AF%E8%A7%86%E5%8C%96/">
                                <span class="chip bg-color">可视化</span>
                            </a>
                        
                            <a href="/tags/%E7%96%AB%E6%83%85%E6%95%B0%E6%8D%AE/">
                                <span class="chip bg-color">疫情数据</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/categories/Python/" class="post-category">
                                Python
                            </a>
                        
                            <a href="/categories/Python/pandas/" class="post-category">
                                pandas
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2021-02-18
                </div>
                

                

                
                <div class="info-break-policy">
                    <i class="far fa-file-word fa-fw"></i>文章字数:&nbsp;&nbsp;
                    2.4k
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-clock fa-fw"></i>阅读时长:&nbsp;&nbsp;
                    12 分
                </div>
                
				
                
                    <div id="busuanzi_container_page_pv" class="info-break-policy">
                        <i class="far fa-eye fa-fw"></i>阅读次数:&nbsp;&nbsp;
                        <span id="busuanzi_value_page_pv"></span>
                    </div>
				
            </div>
            
        </div>
        <hr class="clearfix">
        <div class="card-content article-card-content">
            <div id="articleContent">
                <p>2020年因为新冠疫情而变得特别，我们会看到很多网站都提供了多种疫情统计图，今天我们使用 Python 的 <code>pyecharts</code> 框架来绘制一些比较常见的统计图。</p>
<p>本项目源码已上传至<code>gitee</code>: <a target="_blank" rel="noopener" href="https://gitee.com/zhangyafeii/easy-pandas/tree/master/%E6%A1%88%E4%BE%8B%E7%AF%87/%E6%A1%88%E4%BE%8B%E7%AF%87%EF%BC%9A%E7%96%AB%E6%83%85%E6%95%B0%E6%8D%AE%E5%8F%AF%E8%A7%86%E5%8C%96/">项目地址</a></p>
<h2 id="一、玫瑰图"><a href="#一、玫瑰图" class="headerlink" title="一、玫瑰图"></a>一、玫瑰图</h2><p>首先，我们来绘制前段时间比较火的南丁格尔玫瑰图，数据来源我们通过接口 <code>https://lab.isaaclin.cn/nCoV/zh</code> 来获取，我们取疫情中死亡人数超过 2000 的国家的数据，实现代码如下：</p>
<pre class="line-numbers language-python"><code class="language-python"><span class="token keyword">import</span> datetime
<span class="token keyword">import</span> logging
<span class="token keyword">import</span> random

<span class="token keyword">import</span> requests
<span class="token keyword">from</span> pyecharts <span class="token keyword">import</span> options <span class="token keyword">as</span> opts
<span class="token keyword">from</span> pyecharts<span class="token punctuation">.</span>charts <span class="token keyword">import</span> Pie
<span class="token comment" spellcheck="true"># 导入输出图片工具</span>
<span class="token keyword">from</span> pyecharts<span class="token punctuation">.</span>render <span class="token keyword">import</span> make_snapshot
<span class="token comment" spellcheck="true"># 使用snapshot-selenium 渲染图片</span>
<span class="token keyword">from</span> snapshot_selenium <span class="token keyword">import</span> snapshot


logging<span class="token punctuation">.</span>basicConfig<span class="token punctuation">(</span>level<span class="token operator">=</span>logging<span class="token punctuation">.</span>INFO<span class="token punctuation">,</span> format<span class="token operator">=</span><span class="token string">'%(asctime)s - %(levelname)s: %(message)s'</span><span class="token punctuation">)</span>


<span class="token keyword">def</span> <span class="token function">plot_rose_pie</span><span class="token punctuation">(</span>out_type<span class="token punctuation">:</span> str <span class="token operator">=</span> <span class="token string">'html'</span><span class="token punctuation">,</span> filename<span class="token punctuation">:</span> str <span class="token operator">=</span> <span class="token string">'epidemic_rose_pie'</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
    url <span class="token operator">=</span> <span class="token string">'https://lab.isaaclin.cn/nCoV/api/area'</span>
    data_json <span class="token operator">=</span> requests<span class="token punctuation">.</span>get<span class="token punctuation">(</span>url<span class="token punctuation">)</span><span class="token punctuation">.</span>json<span class="token punctuation">(</span><span class="token punctuation">)</span>
    logging<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string">'get response success, processing plot data...'</span><span class="token punctuation">)</span>
    data <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token keyword">for</span> item <span class="token keyword">in</span> data_json<span class="token punctuation">[</span><span class="token string">'results'</span><span class="token punctuation">]</span><span class="token punctuation">:</span>
        <span class="token keyword">if</span> item<span class="token punctuation">[</span><span class="token string">'countryEnglishName'</span><span class="token punctuation">]</span><span class="token punctuation">:</span>
            <span class="token keyword">if</span> item<span class="token punctuation">[</span><span class="token string">'deadCount'</span><span class="token punctuation">]</span> <span class="token keyword">is</span> <span class="token operator">not</span> None <span class="token operator">and</span> item<span class="token punctuation">[</span><span class="token string">'countryName'</span><span class="token punctuation">]</span> <span class="token keyword">is</span> <span class="token operator">not</span> None<span class="token punctuation">:</span>
                data<span class="token punctuation">[</span>item<span class="token punctuation">[</span><span class="token string">'countryName'</span><span class="token punctuation">]</span><span class="token punctuation">]</span> <span class="token operator">=</span> item<span class="token punctuation">[</span><span class="token string">'deadCount'</span><span class="token punctuation">]</span>

    data <span class="token operator">=</span> dict<span class="token punctuation">(</span>sorted<span class="token punctuation">(</span>data<span class="token punctuation">.</span>items<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> key<span class="token operator">=</span><span class="token keyword">lambda</span> k<span class="token punctuation">:</span> k<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">,</span> reverse<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">)</span><span class="token punctuation">)</span>

    <span class="token comment" spellcheck="true"># 名称有重复的，把国家名作为 key 吧</span>
    country_list <span class="token operator">=</span> list<span class="token punctuation">(</span>data<span class="token punctuation">.</span>keys<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token punctuation">:</span><span class="token number">10</span><span class="token punctuation">]</span>
    count_list <span class="token operator">=</span> list<span class="token punctuation">(</span>data<span class="token punctuation">.</span>values<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token punctuation">:</span><span class="token number">10</span><span class="token punctuation">]</span>
    logging<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string">'data processing completed, ready to draw...'</span><span class="token punctuation">)</span>

    <span class="token comment" spellcheck="true"># 随机颜色生成</span>
    <span class="token keyword">def</span> <span class="token function">randomcolor</span><span class="token punctuation">(</span>kind<span class="token punctuation">)</span><span class="token punctuation">:</span>
        colors <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
        <span class="token keyword">for</span> i <span class="token keyword">in</span> range<span class="token punctuation">(</span>kind<span class="token punctuation">)</span><span class="token punctuation">:</span>
            colArr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token string">'1'</span><span class="token punctuation">,</span> <span class="token string">'2'</span><span class="token punctuation">,</span> <span class="token string">'3'</span><span class="token punctuation">,</span> <span class="token string">'4'</span><span class="token punctuation">,</span> <span class="token string">'5'</span><span class="token punctuation">,</span> <span class="token string">'6'</span><span class="token punctuation">,</span> <span class="token string">'7'</span><span class="token punctuation">,</span> <span class="token string">'8'</span><span class="token punctuation">,</span> <span class="token string">'9'</span><span class="token punctuation">,</span> <span class="token string">'A'</span><span class="token punctuation">,</span> <span class="token string">'B'</span><span class="token punctuation">,</span> <span class="token string">'C'</span><span class="token punctuation">,</span> <span class="token string">'D'</span><span class="token punctuation">,</span> <span class="token string">'E'</span><span class="token punctuation">,</span> <span class="token string">'F'</span><span class="token punctuation">]</span>
            color <span class="token operator">=</span> <span class="token string">""</span>
            <span class="token keyword">for</span> i <span class="token keyword">in</span> range<span class="token punctuation">(</span><span class="token number">6</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
                color <span class="token operator">+=</span> colArr<span class="token punctuation">[</span>random<span class="token punctuation">.</span>randint<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">14</span><span class="token punctuation">)</span><span class="token punctuation">]</span>
            colors<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token string">"#"</span> <span class="token operator">+</span> color<span class="token punctuation">)</span>
        <span class="token keyword">return</span> colors


    color_series <span class="token operator">=</span> randomcolor<span class="token punctuation">(</span>len<span class="token punctuation">(</span>count_list<span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token comment" spellcheck="true"># 创建饼图</span>
    pie <span class="token operator">=</span> Pie<span class="token punctuation">(</span>init_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>InitOpts<span class="token punctuation">(</span>width<span class="token operator">=</span><span class="token string">'800px'</span><span class="token punctuation">,</span> height<span class="token operator">=</span><span class="token string">'900px'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token comment" spellcheck="true"># 添加数据</span>
    pie<span class="token punctuation">.</span>add<span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>list<span class="token punctuation">(</span>z<span class="token punctuation">)</span> <span class="token keyword">for</span> z <span class="token keyword">in</span> zip<span class="token punctuation">(</span>country_list<span class="token punctuation">,</span> count_list<span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            radius<span class="token operator">=</span><span class="token punctuation">[</span><span class="token string">'20%'</span><span class="token punctuation">,</span> <span class="token string">'100%'</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            center<span class="token operator">=</span><span class="token punctuation">[</span><span class="token string">'60%'</span><span class="token punctuation">,</span> <span class="token string">'65%'</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            rosetype<span class="token operator">=</span><span class="token string">'area'</span><span class="token punctuation">)</span>
    <span class="token comment" spellcheck="true"># 设置全局配置</span>
    <span class="token comment" spellcheck="true"># pie.set_global_opts(title_opts=opts.TitleOpts(title='南丁格尔玫瑰图'),</span>
    <span class="token comment" spellcheck="true">#                     legend_opts=opts.LegendOpts(is_show=False))</span>
    <span class="token comment" spellcheck="true"># 设置全局配置项</span>
    date <span class="token operator">=</span> datetime<span class="token punctuation">.</span>datetime<span class="token punctuation">.</span>now<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>strftime<span class="token punctuation">(</span><span class="token string">'%Y-%m-%d'</span><span class="token punctuation">)</span>
    pie<span class="token punctuation">.</span>set_global_opts<span class="token punctuation">(</span>title_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>TitleOpts<span class="token punctuation">(</span>title<span class="token operator">=</span><span class="token string">'全球新冠疫情'</span><span class="token punctuation">,</span> subtitle<span class="token operator">=</span>f<span class="token string">'死亡人数最多\n 的10个国家\n\n{date}'</span><span class="token punctuation">,</span>
                                                  title_textstyle_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>TextStyleOpts<span class="token punctuation">(</span>font_size<span class="token operator">=</span><span class="token number">15</span><span class="token punctuation">,</span> color<span class="token operator">=</span><span class="token string">'#0085c3'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                                                  subtitle_textstyle_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>TextStyleOpts<span class="token punctuation">(</span>font_size<span class="token operator">=</span><span class="token number">12</span><span class="token punctuation">,</span> color<span class="token operator">=</span><span class="token string">'#003399'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                                                  pos_right<span class="token operator">=</span><span class="token string">'center'</span><span class="token punctuation">,</span> pos_left<span class="token operator">=</span><span class="token string">'53%'</span><span class="token punctuation">,</span> pos_top<span class="token operator">=</span><span class="token string">'62%'</span><span class="token punctuation">,</span> pos_bottom<span class="token operator">=</span><span class="token string">'center'</span>
                                                  <span class="token punctuation">)</span><span class="token punctuation">,</span>
                        legend_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>LegendOpts<span class="token punctuation">(</span>is_show<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token comment" spellcheck="true"># 设置系列配置和颜色</span>
    pie<span class="token punctuation">.</span>set_series_opts<span class="token punctuation">(</span>label_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>LabelOpts<span class="token punctuation">(</span>is_show<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">,</span> position<span class="token operator">=</span><span class="token string">'inside'</span><span class="token punctuation">,</span> font_size<span class="token operator">=</span><span class="token number">12</span><span class="token punctuation">,</span>
                                                  formatter<span class="token operator">=</span><span class="token string">'{b}：{c}'</span><span class="token punctuation">,</span> font_style<span class="token operator">=</span><span class="token string">'italic'</span><span class="token punctuation">,</span>
                                                  font_family<span class="token operator">=</span><span class="token string">'Microsoft YaHei'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    pie<span class="token punctuation">.</span>set_colors<span class="token punctuation">(</span>color_series<span class="token punctuation">)</span>
    filename <span class="token operator">=</span> filename<span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token string">'.'</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span>
    <span class="token keyword">if</span> out_type <span class="token operator">==</span> <span class="token string">'html'</span><span class="token punctuation">:</span>
        pie<span class="token punctuation">.</span>render<span class="token punctuation">(</span>f<span class="token string">'{filename}.html'</span><span class="token punctuation">)</span>
    <span class="token keyword">else</span><span class="token punctuation">:</span>
        make_snapshot<span class="token punctuation">(</span>snapshot<span class="token punctuation">,</span> pie<span class="token punctuation">.</span>render<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> f<span class="token string">'{filename}.{out_type}'</span><span class="token punctuation">)</span>
    logging<span class="token punctuation">.</span>info<span class="token punctuation">(</span>f<span class="token string">'{filename}.{out_type} saved success...'</span><span class="token punctuation">)</span>


<span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">'__main__'</span><span class="token punctuation">:</span>
    plot_rose_pie<span class="token punctuation">(</span>filename<span class="token operator">=</span><span class="token string">'epidemic_rose_pie'</span><span class="token punctuation">)</span>
    <span class="token comment" spellcheck="true"># plot_rose_pie(out_type='png', filename='epidemic_rose_pie')</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>运行</p>
<pre class="line-numbers language-bash"><code class="language-bash">2021-02-18 10:40:21,889 - INFO: get response success, processing plot data<span class="token punctuation">..</span>.
2021-02-18 10:40:21,890 - INFO: data processing completed, ready to draw<span class="token punctuation">..</span>.
2021-02-18 10:40:38,487 - INFO: epidemic_rose_pie.html saved success<span class="token punctuation">..</span>.<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre>
<p>效果图</p>
<p><img src="https://zhangyafei-1258643511.cos.ap-nanjing.myqcloud.com/image/epidemic_rose_pie.png"></p>
<h2 id="二、全球疫情地图"><a href="#二、全球疫情地图" class="headerlink" title="二、全球疫情地图"></a>二、全球疫情地图</h2><p>接着我们来绘制全球疫情地图，我们取各个国家的累计死亡人数的数据，代码实现如下所示：</p>
<pre class="line-numbers language-python"><code class="language-python"><span class="token keyword">import</span> datetime
<span class="token keyword">import</span> logging

<span class="token keyword">import</span> requests
<span class="token keyword">from</span> pyecharts <span class="token keyword">import</span> options <span class="token keyword">as</span> opts
<span class="token keyword">from</span> pyecharts<span class="token punctuation">.</span>charts <span class="token keyword">import</span> Map
<span class="token comment" spellcheck="true"># 导入输出图片工具</span>
<span class="token keyword">from</span> pyecharts<span class="token punctuation">.</span>render <span class="token keyword">import</span> make_snapshot
<span class="token comment" spellcheck="true"># 使用snapshot-selenium 渲染图片</span>
<span class="token keyword">from</span> snapshot_selenium <span class="token keyword">import</span> snapshot

logging<span class="token punctuation">.</span>basicConfig<span class="token punctuation">(</span>level<span class="token operator">=</span>logging<span class="token punctuation">.</span>INFO<span class="token punctuation">,</span> format<span class="token operator">=</span><span class="token string">'%(asctime)s - %(levelname)s: %(message)s'</span><span class="token punctuation">)</span>


<span class="token keyword">def</span> <span class="token function">plot_world_map</span><span class="token punctuation">(</span>out_type<span class="token punctuation">:</span> str <span class="token operator">=</span> <span class="token string">'html'</span><span class="token punctuation">,</span> filename<span class="token punctuation">:</span> str <span class="token operator">=</span> <span class="token string">'world_epidemic_map'</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
    url <span class="token operator">=</span> <span class="token string">'https://lab.isaaclin.cn/nCoV/api/area'</span>
    data <span class="token operator">=</span> requests<span class="token punctuation">.</span>get<span class="token punctuation">(</span>url<span class="token punctuation">)</span><span class="token punctuation">.</span>json<span class="token punctuation">(</span><span class="token punctuation">)</span>
    logging<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string">'get response success, processing data...'</span><span class="token punctuation">)</span>
    oversea_confirm <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
    <span class="token keyword">for</span> item <span class="token keyword">in</span> data<span class="token punctuation">[</span><span class="token string">'results'</span><span class="token punctuation">]</span><span class="token punctuation">:</span>
        <span class="token keyword">if</span> item<span class="token punctuation">[</span><span class="token string">'countryEnglishName'</span><span class="token punctuation">]</span><span class="token punctuation">:</span>
            oversea_confirm<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token punctuation">(</span>item<span class="token punctuation">[</span><span class="token string">'countryEnglishName'</span><span class="token punctuation">]</span>
                                    <span class="token punctuation">.</span>replace<span class="token punctuation">(</span><span class="token string">'United States of America'</span><span class="token punctuation">,</span> <span class="token string">'United States'</span><span class="token punctuation">)</span>
                                    <span class="token punctuation">.</span>replace<span class="token punctuation">(</span><span class="token string">'United Kiongdom'</span><span class="token punctuation">,</span> <span class="token string">'United Kingdom'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                                    item<span class="token punctuation">[</span><span class="token string">'deadCount'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    logging<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string">'data processing completed, ready to draw...'</span><span class="token punctuation">)</span>
    date <span class="token operator">=</span> datetime<span class="token punctuation">.</span>datetime<span class="token punctuation">.</span>now<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>strftime<span class="token punctuation">(</span><span class="token string">'%Y-%m-%d'</span><span class="token punctuation">)</span>
    world_map <span class="token operator">=</span> <span class="token punctuation">(</span>
        Map<span class="token punctuation">(</span>init_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>InitOpts<span class="token punctuation">(</span>theme<span class="token operator">=</span><span class="token string">'dark'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
            <span class="token punctuation">.</span>add<span class="token punctuation">(</span><span class="token string">'累计死亡人数'</span><span class="token punctuation">,</span> oversea_confirm<span class="token punctuation">,</span> <span class="token string">'world'</span><span class="token punctuation">,</span> is_map_symbol_show<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">,</span> is_roam<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">)</span>
            <span class="token punctuation">.</span>set_series_opts<span class="token punctuation">(</span>label_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>LabelOpts<span class="token punctuation">(</span>is_show<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">,</span> color<span class="token operator">=</span><span class="token string">'#fff'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
            <span class="token punctuation">.</span>set_global_opts<span class="token punctuation">(</span>
            title_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>TitleOpts<span class="token punctuation">(</span>title<span class="token operator">=</span>f<span class="token string">'全球疫情累计死亡人数地图'</span><span class="token punctuation">,</span> subtitle<span class="token operator">=</span>f<span class="token string">'截止 {date}'</span><span class="token punctuation">,</span>
                                      title_textstyle_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>TextStyleOpts<span class="token punctuation">(</span>font_size<span class="token operator">=</span><span class="token number">15</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                                      subtitle_textstyle_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>TextStyleOpts<span class="token punctuation">(</span>font_size<span class="token operator">=</span><span class="token number">12</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
            legend_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>LegendOpts<span class="token punctuation">(</span>is_show<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
            visualmap_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>VisualMapOpts<span class="token punctuation">(</span>max_<span class="token operator">=</span><span class="token number">2700</span><span class="token punctuation">,</span>
                                              is_piecewise<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">,</span>
                                              pieces<span class="token operator">=</span><span class="token punctuation">[</span>
                                                  <span class="token punctuation">{</span><span class="token string">"max"</span><span class="token punctuation">:</span> <span class="token number">99999</span><span class="token punctuation">,</span> <span class="token string">"min"</span><span class="token punctuation">:</span> <span class="token number">10000</span><span class="token punctuation">,</span> <span class="token string">"label"</span><span class="token punctuation">:</span> <span class="token string">"10000人及以上"</span><span class="token punctuation">,</span>
                                                   <span class="token string">"color"</span><span class="token punctuation">:</span> <span class="token string">"#8A0808"</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
                                                  <span class="token punctuation">{</span><span class="token string">"max"</span><span class="token punctuation">:</span> <span class="token number">9999</span><span class="token punctuation">,</span> <span class="token string">"min"</span><span class="token punctuation">:</span> <span class="token number">1000</span><span class="token punctuation">,</span> <span class="token string">"label"</span><span class="token punctuation">:</span> <span class="token string">"1000-9999人"</span><span class="token punctuation">,</span> <span class="token string">"color"</span><span class="token punctuation">:</span> <span class="token string">"#B40404"</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
                                                  <span class="token punctuation">{</span><span class="token string">"max"</span><span class="token punctuation">:</span> <span class="token number">999</span><span class="token punctuation">,</span> <span class="token string">"min"</span><span class="token punctuation">:</span> <span class="token number">500</span><span class="token punctuation">,</span> <span class="token string">"label"</span><span class="token punctuation">:</span> <span class="token string">"500-999人"</span><span class="token punctuation">,</span> <span class="token string">"color"</span><span class="token punctuation">:</span> <span class="token string">"#DF0101"</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
                                                  <span class="token punctuation">{</span><span class="token string">"max"</span><span class="token punctuation">:</span> <span class="token number">499</span><span class="token punctuation">,</span> <span class="token string">"min"</span><span class="token punctuation">:</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token string">"label"</span><span class="token punctuation">:</span> <span class="token string">"100-499人"</span><span class="token punctuation">,</span> <span class="token string">"color"</span><span class="token punctuation">:</span> <span class="token string">"#F78181"</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
                                                  <span class="token punctuation">{</span><span class="token string">"max"</span><span class="token punctuation">:</span> <span class="token number">99</span><span class="token punctuation">,</span> <span class="token string">"min"</span><span class="token punctuation">:</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">"label"</span><span class="token punctuation">:</span> <span class="token string">"10-99人"</span><span class="token punctuation">,</span> <span class="token string">"color"</span><span class="token punctuation">:</span> <span class="token string">"#F5A9A9"</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
                                                  <span class="token punctuation">{</span><span class="token string">"max"</span><span class="token punctuation">:</span> <span class="token number">9</span><span class="token punctuation">,</span> <span class="token string">"min"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"label"</span><span class="token punctuation">:</span> <span class="token string">"1-9人"</span><span class="token punctuation">,</span> <span class="token string">"color"</span><span class="token punctuation">:</span> <span class="token string">"#FFFFCC"</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
                                              <span class="token punctuation">]</span><span class="token punctuation">)</span>
        <span class="token punctuation">)</span>
    <span class="token punctuation">)</span>
    <span class="token keyword">if</span> out_type <span class="token operator">==</span> <span class="token string">'html'</span><span class="token punctuation">:</span>
        world_map<span class="token punctuation">.</span>render<span class="token punctuation">(</span>f<span class="token string">'{filename}.html'</span><span class="token punctuation">)</span>
    <span class="token keyword">else</span><span class="token punctuation">:</span>
        make_snapshot<span class="token punctuation">(</span>snapshot<span class="token punctuation">,</span> world_map<span class="token punctuation">.</span>render<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> f<span class="token string">'{filename}.{out_type}'</span><span class="token punctuation">)</span>
    logging<span class="token punctuation">.</span>info<span class="token punctuation">(</span>f<span class="token string">'{filename}.{out_type} saved success...'</span><span class="token punctuation">)</span>


<span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">'__main__'</span><span class="token punctuation">:</span>
    plot_world_map<span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token comment" spellcheck="true"># plot_world_map(out_type='png')</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>运行</p>
<pre class="line-numbers language-bash"><code class="language-bash">2021-02-18 11:04:46,447 - INFO: get response success, processing data<span class="token punctuation">..</span>.
2021-02-18 11:04:46,448 - INFO: data processing completed, ready to draw<span class="token punctuation">..</span>.
2021-02-18 11:04:46,504 - INFO: world_epidemic_map.html saved success<span class="token punctuation">..</span>.<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre>
<p>效果图</p>
<p><img src="https://zhangyafei-1258643511.cos.ap-nanjing.myqcloud.com/image/world_epidemic_map.png"></p>
<h2 id="三、中国疫情地图"><a href="#三、中国疫情地图" class="headerlink" title="三、中国疫情地图"></a>三、中国疫情地图</h2><p>我们接着绘制我国的疫情地图，数据取各个省份累计确诊人数的数据，代码实现如下所示：</p>
<pre class="line-numbers language-python"><code class="language-python"><span class="token keyword">import</span> datetime
<span class="token keyword">import</span> logging

<span class="token keyword">import</span> requests
<span class="token keyword">from</span> pyecharts <span class="token keyword">import</span> options <span class="token keyword">as</span> opts
<span class="token keyword">from</span> pyecharts<span class="token punctuation">.</span>charts <span class="token keyword">import</span> Map
<span class="token comment" spellcheck="true"># 导入输出图片工具</span>
<span class="token keyword">from</span> pyecharts<span class="token punctuation">.</span>render <span class="token keyword">import</span> make_snapshot
<span class="token comment" spellcheck="true"># 使用snapshot-selenium 渲染图片</span>
<span class="token keyword">from</span> snapshot_selenium <span class="token keyword">import</span> snapshot

logging<span class="token punctuation">.</span>basicConfig<span class="token punctuation">(</span>level<span class="token operator">=</span>logging<span class="token punctuation">.</span>INFO<span class="token punctuation">,</span> format<span class="token operator">=</span><span class="token string">'%(asctime)s - %(levelname)s: %(message)s'</span><span class="token punctuation">)</span>


<span class="token keyword">def</span> <span class="token function">plot_china_map</span><span class="token punctuation">(</span>out_type<span class="token punctuation">:</span> str <span class="token operator">=</span> <span class="token string">'html'</span><span class="token punctuation">,</span> filename<span class="token punctuation">:</span> str <span class="token operator">=</span> <span class="token string">'china_epidemic_map'</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
    url <span class="token operator">=</span> <span class="token string">'https://lab.isaaclin.cn/nCoV/api/area'</span>
    data <span class="token operator">=</span> requests<span class="token punctuation">.</span>get<span class="token punctuation">(</span>url<span class="token punctuation">)</span><span class="token punctuation">.</span>json<span class="token punctuation">(</span><span class="token punctuation">)</span>
    logging<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string">'get response success, processing data...'</span><span class="token punctuation">)</span>
    province_data <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
    <span class="token keyword">for</span> item <span class="token keyword">in</span> data<span class="token punctuation">[</span><span class="token string">'results'</span><span class="token punctuation">]</span><span class="token punctuation">:</span>
        <span class="token keyword">if</span> item<span class="token punctuation">[</span><span class="token string">'countryName'</span><span class="token punctuation">]</span> <span class="token operator">==</span> <span class="token string">'中国'</span><span class="token punctuation">:</span>
            province_data<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token punctuation">(</span>item<span class="token punctuation">[</span><span class="token string">'provinceShortName'</span><span class="token punctuation">]</span><span class="token punctuation">,</span> item<span class="token punctuation">[</span><span class="token string">'confirmedCount'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">)</span>

    logging<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string">'data processing completed, ready to draw...'</span><span class="token punctuation">)</span>
    date <span class="token operator">=</span> datetime<span class="token punctuation">.</span>datetime<span class="token punctuation">.</span>now<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>strftime<span class="token punctuation">(</span><span class="token string">'%Y-%m-%d'</span><span class="token punctuation">)</span>

    china_map <span class="token operator">=</span> <span class="token punctuation">(</span>
        Map<span class="token punctuation">(</span>init_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>InitOpts<span class="token punctuation">(</span>theme<span class="token operator">=</span><span class="token string">'dark'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
            <span class="token punctuation">.</span>add<span class="token punctuation">(</span><span class="token string">'确诊人数'</span><span class="token punctuation">,</span> province_data<span class="token punctuation">,</span> <span class="token string">'china'</span><span class="token punctuation">,</span> is_map_symbol_show<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">,</span> is_roam<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">)</span>
            <span class="token punctuation">.</span>set_series_opts<span class="token punctuation">(</span>label_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>LabelOpts<span class="token punctuation">(</span>is_show<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">,</span> color<span class="token operator">=</span><span class="token string">'#ffffff'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
            <span class="token punctuation">.</span>set_global_opts<span class="token punctuation">(</span>
            title_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>TitleOpts<span class="token punctuation">(</span>title<span class="token operator">=</span><span class="token string">"中国疫情累计确诊人数地图"</span><span class="token punctuation">,</span> subtitle<span class="token operator">=</span>f<span class="token string">'截止 {date}'</span><span class="token punctuation">,</span>
                                      title_textstyle_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>TextStyleOpts<span class="token punctuation">(</span>font_size<span class="token operator">=</span><span class="token number">15</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                                      subtitle_textstyle_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>TextStyleOpts<span class="token punctuation">(</span>font_size<span class="token operator">=</span><span class="token number">12</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
            legend_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>LegendOpts<span class="token punctuation">(</span>is_show<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
            visualmap_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>VisualMapOpts<span class="token punctuation">(</span>max_<span class="token operator">=</span><span class="token number">2000</span><span class="token punctuation">,</span>
                                              is_piecewise<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">,</span>
                                              pieces<span class="token operator">=</span><span class="token punctuation">[</span>
                                                  <span class="token punctuation">{</span><span class="token string">"max"</span><span class="token punctuation">:</span> <span class="token number">99999</span><span class="token punctuation">,</span> <span class="token string">"min"</span><span class="token punctuation">:</span> <span class="token number">10000</span><span class="token punctuation">,</span> <span class="token string">"label"</span><span class="token punctuation">:</span> <span class="token string">"10000人及以上"</span><span class="token punctuation">,</span> <span class="token string">"color"</span><span class="token punctuation">:</span> <span class="token string">"#8A0808"</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
                                                  <span class="token punctuation">{</span><span class="token string">"max"</span><span class="token punctuation">:</span> <span class="token number">9999</span><span class="token punctuation">,</span> <span class="token string">"min"</span><span class="token punctuation">:</span> <span class="token number">1000</span><span class="token punctuation">,</span> <span class="token string">"label"</span><span class="token punctuation">:</span> <span class="token string">"1000-9999人"</span><span class="token punctuation">,</span> <span class="token string">"color"</span><span class="token punctuation">:</span> <span class="token string">"#B40404"</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
                                                  <span class="token punctuation">{</span><span class="token string">"max"</span><span class="token punctuation">:</span> <span class="token number">999</span><span class="token punctuation">,</span> <span class="token string">"min"</span><span class="token punctuation">:</span> <span class="token number">500</span><span class="token punctuation">,</span> <span class="token string">"label"</span><span class="token punctuation">:</span> <span class="token string">"500-999人"</span><span class="token punctuation">,</span> <span class="token string">"color"</span><span class="token punctuation">:</span> <span class="token string">"#DF0101"</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
                                                  <span class="token punctuation">{</span><span class="token string">"max"</span><span class="token punctuation">:</span> <span class="token number">499</span><span class="token punctuation">,</span> <span class="token string">"min"</span><span class="token punctuation">:</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token string">"label"</span><span class="token punctuation">:</span> <span class="token string">"100-499人"</span><span class="token punctuation">,</span> <span class="token string">"color"</span><span class="token punctuation">:</span> <span class="token string">"#F78181"</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
                                                  <span class="token punctuation">{</span><span class="token string">"max"</span><span class="token punctuation">:</span> <span class="token number">99</span><span class="token punctuation">,</span> <span class="token string">"min"</span><span class="token punctuation">:</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">"label"</span><span class="token punctuation">:</span> <span class="token string">"10-99人"</span><span class="token punctuation">,</span> <span class="token string">"color"</span><span class="token punctuation">:</span> <span class="token string">"#F5A9A9"</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
                                                  <span class="token punctuation">{</span><span class="token string">"max"</span><span class="token punctuation">:</span> <span class="token number">9</span><span class="token punctuation">,</span> <span class="token string">"min"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"label"</span><span class="token punctuation">:</span> <span class="token string">"1-9人"</span><span class="token punctuation">,</span> <span class="token string">"color"</span><span class="token punctuation">:</span> <span class="token string">"#FFFFCC"</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
                                              <span class="token punctuation">]</span><span class="token punctuation">)</span>
        <span class="token punctuation">)</span>
    <span class="token punctuation">)</span>
    <span class="token keyword">if</span> out_type <span class="token operator">==</span> <span class="token string">'html'</span><span class="token punctuation">:</span>
        china_map<span class="token punctuation">.</span>render<span class="token punctuation">(</span>f<span class="token string">'{filename}.html'</span><span class="token punctuation">)</span>
    <span class="token keyword">else</span><span class="token punctuation">:</span>
        make_snapshot<span class="token punctuation">(</span>snapshot<span class="token punctuation">,</span> china_map<span class="token punctuation">.</span>render<span class="token punctuation">(</span>f<span class="token string">'{filename}.html'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> f<span class="token string">'{filename}.{out_type}'</span><span class="token punctuation">)</span>
    logging<span class="token punctuation">.</span>info<span class="token punctuation">(</span>f<span class="token string">'{filename}.{out_type} saved success...'</span><span class="token punctuation">)</span>


<span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">'__main__'</span><span class="token punctuation">:</span>
    <span class="token comment" spellcheck="true"># plot_china_map()</span>
    plot_china_map<span class="token punctuation">(</span>out_type<span class="token operator">=</span><span class="token string">'png'</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>效果图</p>
<p><img src="https://zhangyafei-1258643511.cos.ap-nanjing.myqcloud.com/image/china_epidemic_map.png"></p>
<h2 id="四、柱状图"><a href="#四、柱状图" class="headerlink" title="四、柱状图"></a>四、柱状图</h2><p>我们接着来绘制柱状图，这次我们取一个省份的数据，因为湖北省确诊人数最多，我们就用这个省的数据吧，实现代码如下所示：</p>
<pre class="line-numbers language-python"><code class="language-python"><span class="token keyword">import</span> datetime
<span class="token keyword">import</span> logging

<span class="token keyword">import</span> requests
<span class="token keyword">from</span> pyecharts <span class="token keyword">import</span> options <span class="token keyword">as</span> opts
<span class="token keyword">from</span> pyecharts<span class="token punctuation">.</span>charts <span class="token keyword">import</span> Bar
<span class="token comment" spellcheck="true"># 导入输出图片工具</span>
<span class="token keyword">from</span> pyecharts<span class="token punctuation">.</span>render <span class="token keyword">import</span> make_snapshot
<span class="token comment" spellcheck="true"># 使用snapshot-selenium 渲染图片</span>
<span class="token keyword">from</span> snapshot_selenium <span class="token keyword">import</span> snapshot

logging<span class="token punctuation">.</span>basicConfig<span class="token punctuation">(</span>level<span class="token operator">=</span>logging<span class="token punctuation">.</span>INFO<span class="token punctuation">,</span> format<span class="token operator">=</span><span class="token string">'%(asctime)s - %(levelname)s: %(message)s'</span><span class="token punctuation">)</span>


<span class="token keyword">def</span> <span class="token function">plot_hubei_bar</span><span class="token punctuation">(</span>out_type<span class="token punctuation">:</span> str <span class="token operator">=</span> <span class="token string">'html'</span><span class="token punctuation">,</span> filename<span class="token punctuation">:</span> str <span class="token operator">=</span> <span class="token string">'hubei_epidemic_bar'</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
    url <span class="token operator">=</span> <span class="token string">'https://lab.isaaclin.cn/nCoV/api/area'</span>
    data <span class="token operator">=</span> requests<span class="token punctuation">.</span>get<span class="token punctuation">(</span>url<span class="token punctuation">)</span><span class="token punctuation">.</span>json<span class="token punctuation">(</span><span class="token punctuation">)</span>
    logging<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string">'get response success, processing data...'</span><span class="token punctuation">)</span>
    hb_data <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token keyword">for</span> item <span class="token keyword">in</span> data<span class="token punctuation">[</span><span class="token string">'results'</span><span class="token punctuation">]</span><span class="token punctuation">:</span>
        <span class="token keyword">if</span> item<span class="token punctuation">[</span><span class="token string">'provinceShortName'</span><span class="token punctuation">]</span> <span class="token operator">==</span> <span class="token string">'湖北'</span><span class="token punctuation">:</span>
            hb_data <span class="token operator">=</span> item<span class="token punctuation">[</span><span class="token string">'cities'</span><span class="token punctuation">]</span>
    logging<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string">'data processing completed, ready to draw...'</span><span class="token punctuation">)</span>
    date <span class="token operator">=</span> datetime<span class="token punctuation">.</span>datetime<span class="token punctuation">.</span>now<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>strftime<span class="token punctuation">(</span><span class="token string">'%Y-%m-%d'</span><span class="token punctuation">)</span>
    hb_bar <span class="token operator">=</span> <span class="token punctuation">(</span>
        Bar<span class="token punctuation">(</span>init_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>InitOpts<span class="token punctuation">(</span>theme<span class="token operator">=</span><span class="token string">'dark'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
            <span class="token punctuation">.</span>add_xaxis<span class="token punctuation">(</span><span class="token punctuation">[</span>hd<span class="token punctuation">[</span><span class="token string">'cityName'</span><span class="token punctuation">]</span> <span class="token keyword">for</span> hd <span class="token keyword">in</span> hb_data<span class="token punctuation">]</span><span class="token punctuation">)</span>
            <span class="token punctuation">.</span>add_yaxis<span class="token punctuation">(</span><span class="token string">'累计确诊人数'</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>hd<span class="token punctuation">[</span><span class="token string">'confirmedCount'</span><span class="token punctuation">]</span> <span class="token keyword">for</span> hd <span class="token keyword">in</span> hb_data<span class="token punctuation">]</span><span class="token punctuation">)</span>
            <span class="token punctuation">.</span>add_yaxis<span class="token punctuation">(</span><span class="token string">'累计治愈人数'</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>hd<span class="token punctuation">[</span><span class="token string">'curedCount'</span><span class="token punctuation">]</span> <span class="token keyword">for</span> hd <span class="token keyword">in</span> hb_data<span class="token punctuation">]</span><span class="token punctuation">)</span>
            <span class="token punctuation">.</span>reversal_axis<span class="token punctuation">(</span><span class="token punctuation">)</span>
            <span class="token punctuation">.</span>set_series_opts<span class="token punctuation">(</span>label_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>LabelOpts<span class="token punctuation">(</span>is_show<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
            <span class="token punctuation">.</span>set_global_opts<span class="token punctuation">(</span>
            title_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>TitleOpts<span class="token punctuation">(</span>title<span class="token operator">=</span><span class="token string">"湖北新冠疫情确诊及治愈情况"</span><span class="token punctuation">,</span> subtitle<span class="token operator">=</span>f<span class="token string">'截止 {date}'</span><span class="token punctuation">,</span>
                                      title_textstyle_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>TextStyleOpts<span class="token punctuation">(</span>font_size<span class="token operator">=</span><span class="token number">15</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                                      subtitle_textstyle_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>TextStyleOpts<span class="token punctuation">(</span>font_size<span class="token operator">=</span><span class="token number">12</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
            legend_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>LegendOpts<span class="token punctuation">(</span>is_show<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">)</span>
        <span class="token punctuation">)</span>
    <span class="token punctuation">)</span>
    <span class="token keyword">if</span> out_type <span class="token operator">==</span> <span class="token string">'html'</span><span class="token punctuation">:</span>
        hb_bar<span class="token punctuation">.</span>render<span class="token punctuation">(</span>f<span class="token string">'{filename}.html'</span><span class="token punctuation">)</span>
    <span class="token keyword">else</span><span class="token punctuation">:</span>
        make_snapshot<span class="token punctuation">(</span>snapshot<span class="token punctuation">,</span> hb_bar<span class="token punctuation">.</span>render<span class="token punctuation">(</span>f<span class="token string">'{filename}.html'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> f<span class="token string">'{filename}.{out_type}'</span><span class="token punctuation">)</span>
    logging<span class="token punctuation">.</span>info<span class="token punctuation">(</span>f<span class="token string">'{filename}.{out_type} saved success...'</span><span class="token punctuation">)</span>


<span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">'__main__'</span><span class="token punctuation">:</span>
    <span class="token comment" spellcheck="true"># plot_hubei_bar()</span>
    plot_hubei_bar<span class="token punctuation">(</span>out_type<span class="token operator">=</span><span class="token string">'png'</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>效果图</p>
<p><img src="https://zhangyafei-1258643511.cos.ap-nanjing.myqcloud.com/image/hubei_epidemic_bar.png"></p>
<h2 id="五、折线图"><a href="#五、折线图" class="headerlink" title="五、折线图"></a>五、折线图</h2><p>代码实现如下所示：</p>
<pre class="line-numbers language-python"><code class="language-python"><span class="token keyword">import</span> logging

<span class="token keyword">import</span> pandas <span class="token keyword">as</span> pd
<span class="token keyword">from</span> pyecharts <span class="token keyword">import</span> options <span class="token keyword">as</span> opts
<span class="token keyword">from</span> pyecharts<span class="token punctuation">.</span>charts <span class="token keyword">import</span> Line
<span class="token comment" spellcheck="true"># 导入输出图片工具</span>
<span class="token keyword">from</span> pyecharts<span class="token punctuation">.</span>render <span class="token keyword">import</span> make_snapshot
<span class="token comment" spellcheck="true"># 使用snapshot-selenium 渲染图片</span>
<span class="token keyword">from</span> snapshot_selenium <span class="token keyword">import</span> snapshot

logging<span class="token punctuation">.</span>basicConfig<span class="token punctuation">(</span>level<span class="token operator">=</span>logging<span class="token punctuation">.</span>INFO<span class="token punctuation">,</span> format<span class="token operator">=</span><span class="token string">'%(asctime)s - %(levelname)s: %(message)s'</span><span class="token punctuation">)</span>


<span class="token keyword">def</span> <span class="token function">plot_china_line</span><span class="token punctuation">(</span>out_type<span class="token punctuation">:</span> str <span class="token operator">=</span> <span class="token string">'html'</span><span class="token punctuation">,</span> filename<span class="token punctuation">:</span> str <span class="token operator">=</span> <span class="token string">'china_epidemic_line'</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
    df <span class="token operator">=</span> pd<span class="token punctuation">.</span>read_excel<span class="token punctuation">(</span><span class="token string">'data/china_history.xlsx'</span><span class="token punctuation">,</span> index_col<span class="token operator">=</span><span class="token string">'date'</span><span class="token punctuation">,</span> date_parser<span class="token operator">=</span><span class="token string">'date'</span><span class="token punctuation">)</span>
    df <span class="token operator">=</span> df<span class="token punctuation">.</span>resample<span class="token punctuation">(</span><span class="token string">'15d'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>max<span class="token punctuation">(</span><span class="token punctuation">)</span>
    date <span class="token operator">=</span> df<span class="token punctuation">.</span>index<span class="token punctuation">.</span>strftime<span class="token punctuation">(</span><span class="token string">'%Y-%m-%d'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>to_list<span class="token punctuation">(</span><span class="token punctuation">)</span>
    confirm <span class="token operator">=</span> df<span class="token punctuation">[</span><span class="token string">'confirm'</span><span class="token punctuation">]</span><span class="token punctuation">.</span>to_list<span class="token punctuation">(</span><span class="token punctuation">)</span>
    heal <span class="token operator">=</span> df<span class="token punctuation">[</span><span class="token string">'heal'</span><span class="token punctuation">]</span><span class="token punctuation">.</span>to_list<span class="token punctuation">(</span><span class="token punctuation">)</span>

    logging<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string">'data read completed, ready to draw...'</span><span class="token punctuation">)</span>
    line <span class="token operator">=</span> <span class="token punctuation">(</span>Line<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token punctuation">.</span>add_xaxis<span class="token punctuation">(</span>date<span class="token punctuation">)</span>
        <span class="token punctuation">.</span>add_yaxis<span class="token punctuation">(</span><span class="token string">'累计确诊'</span><span class="token punctuation">,</span> confirm<span class="token punctuation">,</span> color<span class="token operator">=</span><span class="token string">'#10aeb5'</span><span class="token punctuation">)</span>
        <span class="token punctuation">.</span>add_yaxis<span class="token punctuation">(</span><span class="token string">'累计治愈'</span><span class="token punctuation">,</span> heal<span class="token punctuation">,</span> color<span class="token operator">=</span><span class="token string">'#e83132'</span><span class="token punctuation">)</span>
        <span class="token punctuation">.</span>set_series_opts<span class="token punctuation">(</span>label_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>LabelOpts<span class="token punctuation">(</span>is_show<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        <span class="token punctuation">.</span>set_global_opts<span class="token punctuation">(</span>
        title_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>TitleOpts<span class="token punctuation">(</span>title<span class="token operator">=</span><span class="token string">'中国疫情随时间变化趋势'</span><span class="token punctuation">)</span>
    <span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token keyword">if</span> out_type <span class="token operator">==</span> <span class="token string">'html'</span><span class="token punctuation">:</span>
        line<span class="token punctuation">.</span>render<span class="token punctuation">(</span>f<span class="token string">'{filename}.html'</span><span class="token punctuation">)</span>
    <span class="token keyword">else</span><span class="token punctuation">:</span>
        make_snapshot<span class="token punctuation">(</span>snapshot<span class="token punctuation">,</span> line<span class="token punctuation">.</span>render<span class="token punctuation">(</span>f<span class="token string">'{filename}.html'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> f<span class="token string">'{filename}.{out_type}'</span><span class="token punctuation">)</span>
    logging<span class="token punctuation">.</span>info<span class="token punctuation">(</span>f<span class="token string">'{filename}.{out_type} saved success...'</span><span class="token punctuation">)</span>


<span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">'__main__'</span><span class="token punctuation">:</span>
    plot_china_line<span class="token punctuation">(</span>out_type<span class="token operator">=</span><span class="token string">'png'</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>效果图</p>
<p><img src="https://zhangyafei-1258643511.cos.ap-nanjing.myqcloud.com/image/china_epidemic_line.png"></p>
<h2 id="六、全国各省市疫情数据动态图"><a href="#六、全国各省市疫情数据动态图" class="headerlink" title="六、全国各省市疫情数据动态图"></a>六、全国各省市疫情数据动态图</h2><p>数据</p>
<p><img src="https://zhangyafei-1258643511.cos.ap-nanjing.myqcloud.com/image/image-20210221221714902.png"></p>
<p>代码</p>
<pre class="line-numbers language-python"><code class="language-python"><span class="token keyword">import</span> pandas <span class="token keyword">as</span> pd
<span class="token keyword">from</span> pyecharts <span class="token keyword">import</span> options <span class="token keyword">as</span> opts
<span class="token keyword">from</span> pyecharts<span class="token punctuation">.</span>charts <span class="token keyword">import</span> Bar<span class="token punctuation">,</span> Timeline<span class="token punctuation">,</span> Grid
<span class="token keyword">from</span> pyecharts<span class="token punctuation">.</span>globals <span class="token keyword">import</span> ThemeType<span class="token punctuation">,</span> CurrentConfig

CurrentConfig<span class="token punctuation">.</span>ONLINE_HOST <span class="token operator">=</span> <span class="token string">"https://cdn.kesci.com/lib/pyecharts_assets/"</span>

<span class="token keyword">def</span> <span class="token function">plot</span><span class="token punctuation">(</span>file<span class="token punctuation">:</span> str<span class="token punctuation">,</span> name_col<span class="token punctuation">:</span> str<span class="token punctuation">,</span> title<span class="token punctuation">:</span> str<span class="token punctuation">,</span> num<span class="token punctuation">:</span> int <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">,</span> duration<span class="token operator">=</span><span class="token number">1.0</span><span class="token punctuation">,</span> html_path<span class="token punctuation">:</span> str <span class="token operator">=</span> <span class="token string">'render.html'</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
    df <span class="token operator">=</span> pd<span class="token punctuation">.</span>read_excel<span class="token punctuation">(</span>file<span class="token punctuation">,</span> index_col<span class="token operator">=</span>name_col<span class="token punctuation">)</span>
    date_list <span class="token operator">=</span> df<span class="token punctuation">.</span>columns<span class="token punctuation">.</span>to_list<span class="token punctuation">(</span><span class="token punctuation">)</span>

    t <span class="token operator">=</span> Timeline<span class="token punctuation">(</span>init_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>InitOpts<span class="token punctuation">(</span>theme<span class="token operator">=</span>ThemeType<span class="token punctuation">.</span>MACARONS<span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment" spellcheck="true"># 定制主题</span>
    <span class="token keyword">for</span> date <span class="token keyword">in</span> date_list<span class="token punctuation">:</span>
        data <span class="token operator">=</span> df<span class="token punctuation">.</span>sort_values<span class="token punctuation">(</span>date<span class="token punctuation">,</span> ascending<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token punctuation">:</span>num<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span>

        x <span class="token operator">=</span> data<span class="token punctuation">.</span>index<span class="token punctuation">.</span>to_list<span class="token punctuation">(</span><span class="token punctuation">)</span>
        y <span class="token operator">=</span> data<span class="token punctuation">[</span>date<span class="token punctuation">]</span><span class="token punctuation">.</span>to_list<span class="token punctuation">(</span><span class="token punctuation">)</span>

        bar <span class="token operator">=</span> <span class="token punctuation">(</span>
            Bar<span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span>add_xaxis<span class="token punctuation">(</span>x<span class="token punctuation">)</span>  <span class="token comment" spellcheck="true"># x轴数据</span>
                <span class="token punctuation">.</span>add_yaxis<span class="token punctuation">(</span><span class="token string">'确诊人数'</span><span class="token punctuation">,</span> y<span class="token punctuation">)</span>  <span class="token comment" spellcheck="true"># y轴数据</span>
                <span class="token punctuation">.</span>reversal_axis<span class="token punctuation">(</span><span class="token punctuation">)</span>  <span class="token comment" spellcheck="true"># 翻转</span>
                <span class="token punctuation">.</span>set_global_opts<span class="token punctuation">(</span>  <span class="token comment" spellcheck="true"># 全局配置项</span>
                title_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>TitleOpts<span class="token punctuation">(</span>  <span class="token comment" spellcheck="true"># 标题配置项</span>
                    title<span class="token operator">=</span>f<span class="token string">'{title}(日期：{date})'</span><span class="token punctuation">,</span>
                    pos_right<span class="token operator">=</span><span class="token string">"5%"</span><span class="token punctuation">,</span> pos_bottom<span class="token operator">=</span><span class="token string">"15%"</span><span class="token punctuation">,</span>
                    title_textstyle_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>TextStyleOpts<span class="token punctuation">(</span>
                        font_family<span class="token operator">=</span><span class="token string">'KaiTi'</span><span class="token punctuation">,</span> font_size<span class="token operator">=</span><span class="token number">24</span><span class="token punctuation">,</span> color<span class="token operator">=</span><span class="token string">'#FF1493'</span>
                    <span class="token punctuation">)</span>
                <span class="token punctuation">)</span><span class="token punctuation">,</span>
                xaxis_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>AxisOpts<span class="token punctuation">(</span>  <span class="token comment" spellcheck="true"># x轴配置项</span>
                    splitline_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>SplitLineOpts<span class="token punctuation">(</span>is_show<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                <span class="token punctuation">)</span><span class="token punctuation">,</span>
                yaxis_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>AxisOpts<span class="token punctuation">(</span>  <span class="token comment" spellcheck="true"># y轴配置项</span>
                    splitline_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>SplitLineOpts<span class="token punctuation">(</span>is_show<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                    axislabel_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>LabelOpts<span class="token punctuation">(</span>color<span class="token operator">=</span><span class="token string">'#DC143C'</span><span class="token punctuation">)</span>
                <span class="token punctuation">)</span>
            <span class="token punctuation">)</span>
                <span class="token punctuation">.</span>set_series_opts<span class="token punctuation">(</span>  <span class="token comment" spellcheck="true"># 系列配置项</span>
                label_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>LabelOpts<span class="token punctuation">(</span>  <span class="token comment" spellcheck="true"># 标签配置</span>
                    position<span class="token operator">=</span><span class="token string">"right"</span><span class="token punctuation">,</span> color<span class="token operator">=</span><span class="token string">'#9400D3'</span><span class="token punctuation">)</span>
            <span class="token punctuation">)</span>
        <span class="token punctuation">)</span>
        grid <span class="token operator">=</span> <span class="token punctuation">(</span>
            Grid<span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span>add<span class="token punctuation">(</span>bar<span class="token punctuation">,</span> grid_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>GridOpts<span class="token punctuation">(</span>pos_left<span class="token operator">=</span><span class="token string">"24%"</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        <span class="token punctuation">)</span>

        t<span class="token punctuation">.</span>add<span class="token punctuation">(</span>grid<span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
        t<span class="token punctuation">.</span>add_schema<span class="token punctuation">(</span>
            play_interval<span class="token operator">=</span>duration <span class="token operator">*</span> <span class="token number">1000</span><span class="token punctuation">,</span>  <span class="token comment" spellcheck="true"># 轮播速度</span>
            is_timeline_show<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">,</span>  <span class="token comment" spellcheck="true"># 是否显示 timeline 组件</span>
            is_auto_play<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">,</span>  <span class="token comment" spellcheck="true"># 是否自动播放</span>
        <span class="token punctuation">)</span>

    t<span class="token punctuation">.</span>render<span class="token punctuation">(</span>html_path<span class="token punctuation">)</span>

<span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">'__main__'</span><span class="token punctuation">:</span>
    plot<span class="token punctuation">(</span>html_path<span class="token operator">=</span><span class="token string">'各省份每日确诊人数动态图.html'</span><span class="token punctuation">,</span> file<span class="token operator">=</span><span class="token string">'data/covid19_province_data.xlsx.xlsx'</span><span class="token punctuation">,</span> name_col<span class="token operator">=</span><span class="token string">'省级行政区'</span><span class="token punctuation">,</span> title<span class="token operator">=</span><span class="token string">'全国各省市新冠数据'</span><span class="token punctuation">,</span> duration<span class="token operator">=</span><span class="token number">0.3</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p><img src="https://zhangyafei-1258643511.cos.ap-nanjing.myqcloud.com/image/province_data.gif"></p>
<h2 id="七、世界各国疫情数据动态图"><a href="#七、世界各国疫情数据动态图" class="headerlink" title="七、世界各国疫情数据动态图"></a>七、世界各国疫情数据动态图</h2><p>数据</p>
<p><img src="https://zhangyafei-1258643511.cos.ap-nanjing.myqcloud.com/image/image-20210221221837916.png"></p>
<p>代码</p>
<pre class="line-numbers language-python"><code class="language-python"><span class="token keyword">import</span> pandas <span class="token keyword">as</span> pd
<span class="token keyword">from</span> pyecharts <span class="token keyword">import</span> options <span class="token keyword">as</span> opts
<span class="token keyword">from</span> pyecharts<span class="token punctuation">.</span>charts <span class="token keyword">import</span> Bar<span class="token punctuation">,</span> Timeline<span class="token punctuation">,</span> Grid
<span class="token keyword">from</span> pyecharts<span class="token punctuation">.</span>globals <span class="token keyword">import</span> ThemeType<span class="token punctuation">,</span> CurrentConfig

CurrentConfig<span class="token punctuation">.</span>ONLINE_HOST <span class="token operator">=</span> <span class="token string">"https://cdn.kesci.com/lib/pyecharts_assets/"</span>

<span class="token keyword">def</span> <span class="token function">plot</span><span class="token punctuation">(</span>file<span class="token punctuation">:</span> str<span class="token punctuation">,</span> name_col<span class="token punctuation">:</span> str<span class="token punctuation">,</span> title<span class="token punctuation">:</span> str<span class="token punctuation">,</span> num<span class="token punctuation">:</span> int <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">,</span> duration<span class="token operator">=</span><span class="token number">1.0</span><span class="token punctuation">,</span> html_path<span class="token punctuation">:</span> str <span class="token operator">=</span> <span class="token string">'render.html'</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
    df <span class="token operator">=</span> pd<span class="token punctuation">.</span>read_excel<span class="token punctuation">(</span>file<span class="token punctuation">,</span> index_col<span class="token operator">=</span>name_col<span class="token punctuation">)</span>
    date_list <span class="token operator">=</span> df<span class="token punctuation">.</span>columns<span class="token punctuation">.</span>to_list<span class="token punctuation">(</span><span class="token punctuation">)</span>

    t <span class="token operator">=</span> Timeline<span class="token punctuation">(</span>init_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>InitOpts<span class="token punctuation">(</span>theme<span class="token operator">=</span>ThemeType<span class="token punctuation">.</span>MACARONS<span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment" spellcheck="true"># 定制主题</span>
    <span class="token keyword">for</span> date <span class="token keyword">in</span> date_list<span class="token punctuation">:</span>
        data <span class="token operator">=</span> df<span class="token punctuation">.</span>sort_values<span class="token punctuation">(</span>date<span class="token punctuation">,</span> ascending<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token punctuation">:</span>num<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span>

        x <span class="token operator">=</span> data<span class="token punctuation">.</span>index<span class="token punctuation">.</span>to_list<span class="token punctuation">(</span><span class="token punctuation">)</span>
        y <span class="token operator">=</span> data<span class="token punctuation">[</span>date<span class="token punctuation">]</span><span class="token punctuation">.</span>to_list<span class="token punctuation">(</span><span class="token punctuation">)</span>

        bar <span class="token operator">=</span> <span class="token punctuation">(</span>
            Bar<span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span>add_xaxis<span class="token punctuation">(</span>x<span class="token punctuation">)</span>  <span class="token comment" spellcheck="true"># x轴数据</span>
                <span class="token punctuation">.</span>add_yaxis<span class="token punctuation">(</span><span class="token string">'确诊人数'</span><span class="token punctuation">,</span> y<span class="token punctuation">)</span>  <span class="token comment" spellcheck="true"># y轴数据</span>
                <span class="token punctuation">.</span>reversal_axis<span class="token punctuation">(</span><span class="token punctuation">)</span>  <span class="token comment" spellcheck="true"># 翻转</span>
                <span class="token punctuation">.</span>set_global_opts<span class="token punctuation">(</span>  <span class="token comment" spellcheck="true"># 全局配置项</span>
                title_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>TitleOpts<span class="token punctuation">(</span>  <span class="token comment" spellcheck="true"># 标题配置项</span>
                    title<span class="token operator">=</span>f<span class="token string">'{title}(日期：{date})'</span><span class="token punctuation">,</span>
                    pos_right<span class="token operator">=</span><span class="token string">"5%"</span><span class="token punctuation">,</span> pos_bottom<span class="token operator">=</span><span class="token string">"15%"</span><span class="token punctuation">,</span>
                    title_textstyle_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>TextStyleOpts<span class="token punctuation">(</span>
                        font_family<span class="token operator">=</span><span class="token string">'KaiTi'</span><span class="token punctuation">,</span> font_size<span class="token operator">=</span><span class="token number">24</span><span class="token punctuation">,</span> color<span class="token operator">=</span><span class="token string">'#FF1493'</span>
                    <span class="token punctuation">)</span>
                <span class="token punctuation">)</span><span class="token punctuation">,</span>
                xaxis_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>AxisOpts<span class="token punctuation">(</span>  <span class="token comment" spellcheck="true"># x轴配置项</span>
                    splitline_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>SplitLineOpts<span class="token punctuation">(</span>is_show<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                <span class="token punctuation">)</span><span class="token punctuation">,</span>
                yaxis_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>AxisOpts<span class="token punctuation">(</span>  <span class="token comment" spellcheck="true"># y轴配置项</span>
                    splitline_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>SplitLineOpts<span class="token punctuation">(</span>is_show<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                    axislabel_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>LabelOpts<span class="token punctuation">(</span>color<span class="token operator">=</span><span class="token string">'#DC143C'</span><span class="token punctuation">)</span>
                <span class="token punctuation">)</span>
            <span class="token punctuation">)</span>
                <span class="token punctuation">.</span>set_series_opts<span class="token punctuation">(</span>  <span class="token comment" spellcheck="true"># 系列配置项</span>
                label_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>LabelOpts<span class="token punctuation">(</span>  <span class="token comment" spellcheck="true"># 标签配置</span>
                    position<span class="token operator">=</span><span class="token string">"right"</span><span class="token punctuation">,</span> color<span class="token operator">=</span><span class="token string">'#9400D3'</span><span class="token punctuation">)</span>
            <span class="token punctuation">)</span>
        <span class="token punctuation">)</span>
        grid <span class="token operator">=</span> <span class="token punctuation">(</span>
            Grid<span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span>add<span class="token punctuation">(</span>bar<span class="token punctuation">,</span> grid_opts<span class="token operator">=</span>opts<span class="token punctuation">.</span>GridOpts<span class="token punctuation">(</span>pos_left<span class="token operator">=</span><span class="token string">"24%"</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        <span class="token punctuation">)</span>

        t<span class="token punctuation">.</span>add<span class="token punctuation">(</span>grid<span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
        t<span class="token punctuation">.</span>add_schema<span class="token punctuation">(</span>
            play_interval<span class="token operator">=</span>duration <span class="token operator">*</span> <span class="token number">1000</span><span class="token punctuation">,</span>  <span class="token comment" spellcheck="true"># 轮播速度</span>
            is_timeline_show<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">,</span>  <span class="token comment" spellcheck="true"># 是否显示 timeline 组件</span>
            is_auto_play<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">,</span>  <span class="token comment" spellcheck="true"># 是否自动播放</span>
        <span class="token punctuation">)</span>

    t<span class="token punctuation">.</span>render<span class="token punctuation">(</span>html_path<span class="token punctuation">)</span>


<span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">'__main__'</span><span class="token punctuation">:</span>  
    plot<span class="token punctuation">(</span>html_path<span class="token operator">=</span><span class="token string">'世界各国新冠疫情数据动态图.html'</span><span class="token punctuation">,</span> file<span class="token operator">=</span><span class="token string">'data/covid19_country_data.xlsx'</span><span class="token punctuation">,</span> name_col<span class="token operator">=</span><span class="token string">'countryName'</span><span class="token punctuation">,</span> title<span class="token operator">=</span><span class="token string">'世界各国新冠数据'</span><span class="token punctuation">,</span> duration<span class="token operator">=</span><span class="token number">0.3</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p><img src="https://zhangyafei-1258643511.cos.ap-nanjing.myqcloud.com/image/country_data.gif"></p>

            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://zhangyafeii.gitee.io" rel="external nofollow noreferrer">张亚飞</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://zhangyafeii.gitee.io/python/pandas/yi-qing-shu-ju-ke-shi-hua/">https://zhangyafeii.gitee.io/python/pandas/yi-qing-shu-ju-ke-shi-hua/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="https://zhangyafeii.gitee.io" target="_blank">张亚飞</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/tags/Python%E4%B9%8B%E8%B7%AF/">
                                    <span class="chip bg-color">Python之路</span>
                                </a>
                            
                                <a href="/tags/%E7%88%AC%E8%99%AB/">
                                    <span class="chip bg-color">爬虫</span>
                                </a>
                            
                                <a href="/tags/pandas/">
                                    <span class="chip bg-color">pandas</span>
                                </a>
                            
                                <a href="/tags/%E6%A1%88%E4%BE%8B%E7%AF%87/">
                                    <span class="chip bg-color">案例篇</span>
                                </a>
                            
                                <a href="/tags/%E5%8F%AF%E8%A7%86%E5%8C%96/">
                                    <span class="chip bg-color">可视化</span>
                                </a>
                            
                                <a href="/tags/%E7%96%AB%E6%83%85%E6%95%B0%E6%8D%AE/">
                                    <span class="chip bg-color">疫情数据</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">

<div id="article-share">
    
    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
                <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.4rem;
        line-height: 38px;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="/medias/reward/alipay.jpg" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="/medias/reward/wechat.png" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>
            
        </div>
    </div>

    
        <link rel="stylesheet" href="/libs/gitalk/gitalk.css">
<link rel="stylesheet" href="/css/my-gitalk.css">

<div class="card gitalk-card" data-aos="fade-up">
    <div class="comment_headling" style="font-size: 20px; font-weight: 700; position: relative; left: 20px; top: 15px; padding-bottom: 5px;">
        <i class="fas fa-comments fa-fw" aria-hidden="true"></i>
        <span>评论</span>
    </div>
    <div id="gitalk-container" class="card-content"></div>
</div>

<script src="/libs/gitalk/gitalk.min.js"></script>
<script>
    let gitalk = new Gitalk({
        clientID: 'b9bf0e29501275f4f23c',
        clientSecret: '1c56bc88fdb7b23ee3712916a38e5e8d1311823a',
        repo: 'github.io',
        owner: 'zhangyafeii',
        admin: "zhangyafeii",
        id: '2021-02-18T10-00-00',
        distractionFreeMode: false  // Facebook-like distraction free mode
    });

    gitalk.render('gitalk-container');
</script>
    

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/python/pandas/pyecharts-ke-shi-hua-jiao-cheng/">
                    <div class="card-image">
                        
                        <img src="https://zhangyafei-1258643511.cos.ap-nanjing.myqcloud.com/Python/blog/pandas-8.jpg" class="responsive-img" alt="进阶篇：pyecharts可视化教程（一）">
                        
                        <span class="card-title">进阶篇：pyecharts可视化教程（一）</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            看 PyEcharts 名字就猜得到，PyEcharts = Python + Echarts。Echarts 是一个由百度开源的数据可视化工具，凭借着良好的交互性，精巧的图表设计，得到了众多开发者的认可，而 Python 就不用多说了。当
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2021-02-18
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/Python/" class="post-category">
                                    Python
                                </a>
                            
                            <a href="/categories/Python/pandas/" class="post-category">
                                    pandas
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/Python%E4%B9%8B%E8%B7%AF/">
                        <span class="chip bg-color">Python之路</span>
                    </a>
                    
                    <a href="/tags/%E8%BF%9B%E9%98%B6%E7%AF%87/">
                        <span class="chip bg-color">进阶篇</span>
                    </a>
                    
                    <a href="/tags/pandas/">
                        <span class="chip bg-color">pandas</span>
                    </a>
                    
                    <a href="/tags/%E5%8F%AF%E8%A7%86%E5%8C%96/">
                        <span class="chip bg-color">可视化</span>
                    </a>
                    
                    <a href="/tags/pyecharts/">
                        <span class="chip bg-color">pyecharts</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/python/pandas/wei-bo-re-sou-shu-ju-pa-qu-ji-dong-tai-tu-hui-zhi/">
                    <div class="card-image">
                        
                        <img src="https://zhangyafei-1258643511.cos.ap-nanjing.myqcloud.com/Python/blog/pandas-6.jpg" class="responsive-img" alt="案例篇：微博热搜数据爬取及动态图绘制">
                        
                        <span class="card-title">案例篇：微博热搜数据爬取及动态图绘制</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            本项目源码已上传至gitee: 项目地址
一、schedule模块定时执行任务python中有一个轻量级的定时任务调度的库：schedule。他可以完成每分钟，每小时，每天，周几，特定日期的定时任务。因此十分方便我们执行一些轻量级的定时任务
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2021-02-17
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/Python/" class="post-category">
                                    Python
                                </a>
                            
                            <a href="/categories/Python/pandas/" class="post-category">
                                    pandas
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/Python%E4%B9%8B%E8%B7%AF/">
                        <span class="chip bg-color">Python之路</span>
                    </a>
                    
                    <a href="/tags/%E7%88%AC%E8%99%AB/">
                        <span class="chip bg-color">爬虫</span>
                    </a>
                    
                    <a href="/tags/pandas/">
                        <span class="chip bg-color">pandas</span>
                    </a>
                    
                    <a href="/tags/%E6%A1%88%E4%BE%8B%E7%AF%87/">
                        <span class="chip bg-color">案例篇</span>
                    </a>
                    
                    <a href="/tags/%E5%BE%AE%E5%8D%9A%E7%83%AD%E6%90%9C/">
                        <span class="chip bg-color">微博热搜</span>
                    </a>
                    
                    <a href="/tags/%E5%8F%AF%E8%A7%86%E5%8C%96/">
                        <span class="chip bg-color">可视化</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>


<script>
    $('#articleContent').on('copy', function (e) {
        // IE8 or earlier browser is 'undefined'
        if (typeof window.getSelection === 'undefined') return;

        var selection = window.getSelection();
        // if the selection is short let's not annoy our users.
        if (('' + selection).length < Number.parseInt('120')) {
            return;
        }

        // create a div outside of the visible area and fill it with the selected text.
        var bodyElement = document.getElementsByTagName('body')[0];
        var newdiv = document.createElement('div');
        newdiv.style.position = 'absolute';
        newdiv.style.left = '-99999px';
        bodyElement.appendChild(newdiv);
        newdiv.appendChild(selection.getRangeAt(0).cloneContents());

        // we need a <pre> tag workaround.
        // otherwise the text inside "pre" loses all the line breaks!
        if (selection.getRangeAt(0).commonAncestorContainer.nodeName === 'PRE') {
            newdiv.innerHTML = "<pre>" + newdiv.innerHTML + "</pre>";
        }

        var url = document.location.href;
        newdiv.innerHTML += '<br />'
            + '来源: 飞凡空间<br />'
            + '文章作者: 张亚飞<br />'
            + '文章链接: <a href="' + url + '">' + url + '</a><br />'
            + '本文章著作权归作者所有，任何形式的转载都请注明出处。';

        selection.selectAllChildren(newdiv);
        window.setTimeout(function () {bodyElement.removeChild(newdiv);}, 200);
    });
</script>


<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="/libs/codeBlock/codeLang.js"></script>

    
<!-- 代码块复制 -->

<script type="text/javascript" src="/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/libs/codeBlock/codeShrink.js"></script>


<!-- 代码块折行 -->

<style type="text/css">
code[class*="language-"], pre[class*="language-"] { white-space: pre !important; }
</style>

    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            // headingsOffset: -205,
            headingSelector: 'h2, h3, h4'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h2, h3, h4').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>



    <footer class="page-footer bg-color">
    <div class="container row center-align">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            <span id="year">年份</span>
            <a href="https://zhangyafeii.gitee.io" target="_blank">张亚飞</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a>
            <br>
            
            &nbsp;<i class="fas fa-chart-area"></i>&nbsp;站点总字数:&nbsp;<span
                class="white-color">344.5k</span>&nbsp;字
            
            
            
            
            
            
            <span id="busuanzi_container_site_pv">
                |&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;<span id="busuanzi_value_site_pv"
                    class="white-color"></span>&nbsp;次
            </span>
            
            
            <span id="busuanzi_container_site_uv">
                |&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;<span id="busuanzi_value_site_uv"
                    class="white-color"></span>&nbsp;人
            </span>
            
            <br>
            
            <span id="sitetime">载入运行时间...</span>
            <script>
                function siteTime() {
                    window.setTimeout("siteTime()", 1000);
                    var seconds = 1000;
                    var minutes = seconds * 60;
                    var hours = minutes * 60;
                    var days = hours * 24;
                    var years = days * 365;
                    var today = new Date();
                    var startYear = "2020";
                    var startMonth = "12";
                    var startDate = "18";
                    var startHour = "12";
                    var startMinute = "12";
                    var startSecond = "12";
                    var todayYear = today.getFullYear();
                    var todayMonth = today.getMonth() + 1;
                    var todayDate = today.getDate();
                    var todayHour = today.getHours();
                    var todayMinute = today.getMinutes();
                    var todaySecond = today.getSeconds();
                    var t1 = Date.UTC(startYear, startMonth, startDate, startHour, startMinute, startSecond);
                    var t2 = Date.UTC(todayYear, todayMonth, todayDate, todayHour, todayMinute, todaySecond);
                    var diff = t2 - t1;
                    var diffYears = Math.floor(diff / years);
                    var diffDays = Math.floor((diff / days) - diffYears * 365);
                    var diffHours = Math.floor((diff - (diffYears * 365 + diffDays) * days) / hours);
                    var diffMinutes = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours) /
                        minutes);
                    var diffSeconds = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours -
                        diffMinutes * minutes) / seconds);
                    if (startYear == todayYear) {
                        document.getElementById("year").innerHTML = todayYear;
                        document.getElementById("sitetime").innerHTML = "本站已安全运行 " + diffDays + " 天 " + diffHours +
                            " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒";
                    } else {
                        document.getElementById("year").innerHTML = startYear + " - " + todayYear;
                        document.getElementById("sitetime").innerHTML = "本站已安全运行 " + diffYears + " 年 " + diffDays +
                            " 天 " + diffHours + " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒";
                    }
                }
                setInterval(siteTime, 1000);
            </script>
            
            <br>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/zhangyafeii" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="https://gitee.com/zhangyafeii" class="tooltipped" target="_blank" data-tooltip="访问我的Gitee" data-position="top" data-delay="50">
        <i class="fab fa-google-plus"></i>
    </a>



    <a href="mailto:zhangyafeii@foxmail.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=1271570224" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 1271570224" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>







    <a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>

</div>
    </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script src="/js/search.js"></script>
<script type="text/javascript">
$(function () {
    searchFunc("/" + "search.xml", 'searchInput', 'searchResult');
});
</script>
    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/libs/materialize/materialize.min.js"></script>
    <script src="/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/libs/aos/aos.js"></script>
    <script src="/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/js/matery.js"></script>
    <script src="/js/cursor.js"></script>

    <!-- Global site tag (gtag.js) - Google Analytics -->


    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    

    

    
    <script type="text/javascript" src="/libs/background/ribbon-dynamic.js" async="async"></script>
    
    
    
    <script src="/libs/instantpage/instantpage.js" type="module"></script>
    

</body>

</html>
